﻿Imports System.Data.SqlClient

Public Class clsMovimientos
    Private mintIdMovimiento As Integer
    Private mintIdAdeudo As Integer
    Private mintIdEmpleado As Integer
    Private mintIdNomina As Integer
    Private mdatFecha As Date
    Private mdblMonto As Double
    Private mintTipo As Integer
    Public Property IdMovimiento() As Integer
        Get
            Return mintIdMovimiento
        End Get
        Set(ByVal value As Integer)
            mintIdMovimiento = value
        End Set
    End Property
    Public Property IDAdeudo() As Integer
        Get
            Return mintIdAdeudo
        End Get
        Set(ByVal value As Integer)
            mintIdAdeudo = value
        End Set
    End Property
    Public Property IdEmpleado() As Integer
        Get
            Return mintIdEmpleado
        End Get
        Set(ByVal value As Integer)
            mintIdEmpleado = value
        End Set
    End Property
    Public Property IdNomina() As Integer
        Get
            Return mintIdNomina
        End Get
        Set(ByVal value As Integer)
            mintIdNomina = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Monto() As Double
        Get
            Return mdblMonto
        End Get
        Set(ByVal value As Double)
            mdblMonto = value
        End Set
    End Property
    Public Property Tipo() As Integer
        Get
            Return mintTipo
        End Get
        Set(ByVal value As Integer)
            mintTipo = value
        End Set
    End Property
    Public Sub New()
        mintIdMovimiento = 0
        mintIdAdeudo = 0
        mintIdEmpleado = 0
        mintIdNomina = 0
        mdatFecha = Now()
        mdblMonto = 0
        mintTipo = 0
    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Movimientos Where IDCargo = " & IdMovimiento)
    End Sub
     Public Sub Insertar()
        Dim sql As String = "Insert Into Movimientos (" & _
                            "IdMovimiento," & _
                            "IdAdeudo," & _
                            "IdEmpleado," & _
                            "IdNomina," & _
                            "Fecha," & _
                            "Monto," & _
                            "Tipo)" & _
                            "VALUES (" & _
                            "@IdMovimiento," & _
                            "@IdAdeudo," & _
                            "@IdEmpleado," & _
                            "@IdNomina," & _
                            "@Fecha," & _
                            "@Monto," & _
                            "@Tipo)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdMovimiento", mintIdMovimiento)
        Command.Parameters.AddWithValue("IdAdeudo", mintIdAdeudo)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("IdNomina", mintIdNomina)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Monto", mdblMonto)
        Command.Parameters.AddWithValue("Tipo", mintTipo)


        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
